Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Data
Imports Microsoft.Win32


Namespace ChangeWallpaper
 'ToDo: Nested imports must be moved to top of file
Imports System.Net
    _
   
   '/ <summary>
   '/ Summary description for Form1.
   '/ </summary>
   Public Class Form1
      Inherits System.Windows.Forms.Form
      Private textBox1 As System.Windows.Forms.TextBox
      Private btnBrowse As System.Windows.Forms.Button
      Private btnApply As System.Windows.Forms.Button
      Private openFileDialog1 As System.Windows.Forms.OpenFileDialog
      Private comboBox1 As System.Windows.Forms.ComboBox
      '/ <summary>
      '/ Required designer variable.
      '/ </summary>
      Private components As System.ComponentModel.Container = Nothing
      
      
      Public Sub New()
         '
         ' Required for Windows Form Designer support
         '
         InitializeComponent()
      End Sub 'New
       
      '
      ' TODO: Add any constructor code after InitializeComponent call
      '
      
      '/ <summary>
      '/ Clean up any resources being used.
      '/ </summary>
      Protected Overrides Sub Dispose(disposing As Boolean)
         If disposing Then
            If Not (components Is Nothing) Then
               components.Dispose()
            End If
         End If
         MyBase.Dispose(disposing)
      End Sub 'Dispose
      
      
      '
      'ToDo: Error processing original source shown below
      '
      '
      '-----^--- Pre-processor directives not translated
      '/ <summary>
      '
      'ToDo: Error processing original source shown below
      '
      '
      '--^--- Unexpected pre-processor directive
      '/ Required method for Designer support - do not modify
      '/ the contents of this method with the code editor.
      '/ </summary>
      Private Sub InitializeComponent()
         Me.textBox1 = New System.Windows.Forms.TextBox()
         Me.btnBrowse = New System.Windows.Forms.Button()
         Me.btnApply = New System.Windows.Forms.Button()
         Me.openFileDialog1 = New System.Windows.Forms.OpenFileDialog()
         Me.comboBox1 = New System.Windows.Forms.ComboBox()
         Me.SuspendLayout()
         ' 
         ' textBox1
         ' 
         Me.textBox1.Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles)
         Me.textBox1.Location = New System.Drawing.Point(8, 8)
         Me.textBox1.Name = "textBox1"
         Me.textBox1.Size = New System.Drawing.Size(312, 20)
         Me.textBox1.TabIndex = 0
         Me.textBox1.Text = "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\winter." + "jpg"
         ' 
         ' btnBrowse
         ' 
         Me.btnBrowse.Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles)
         Me.btnBrowse.Location = New System.Drawing.Point(336, 8)
         Me.btnBrowse.Name = "btnBrowse"
         Me.btnBrowse.TabIndex = 1
         Me.btnBrowse.Text = "&Browse"
         ' 
         ' btnApply
         ' 
         Me.btnApply.Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles)
         Me.btnApply.Location = New System.Drawing.Point(360, 64)
         Me.btnApply.Name = "btnApply"
         Me.btnApply.TabIndex = 1
         Me.btnApply.Text = "&Apply"
         ' 
         ' comboBox1
         ' 
         Me.comboBox1.Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles)
         Me.comboBox1.Items.AddRange(New Object() {"Stretched", "Centered", "Tiled"})
         Me.comboBox1.Location = New System.Drawing.Point(8, 40)
         Me.comboBox1.Name = "comboBox1"
         Me.comboBox1.Size = New System.Drawing.Size(312, 21)
         Me.comboBox1.TabIndex = 2
         Me.comboBox1.Text = "Stretched"
         ' 
         ' Form1
         ' 
         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
         Me.ClientSize = New System.Drawing.Size(440, 94)
         Me.Controls.Add(comboBox1)
         Me.Controls.Add(btnBrowse)
         Me.Controls.Add(textBox1)
         Me.Controls.Add(btnApply)
         Me.Name = "Form1"
         Me.Text = "Form1"
         Me.ResumeLayout(False)
      End Sub 'InitializeComponent
       
      '
      'ToDo: Error processing original source shown below
      '
      '
      '-----^--- Pre-processor directives not translated
      '
      'ToDo: Error processing original source shown below
      '
      '
      '--^--- Unexpected pre-processor directive
      '/ <summary>
      '/ The main entry point for the application.
      '/ </summary>
      Shared<STAThread()>  _
      Sub Main()
         Application.Run(New Form1())
      End Sub 'Main
      
      
      Private Sub btnBrowse_Click(sender As Object, e As System.EventArgs) Handles Me.btnBrowse.Click
         openFileDialog1.InitialDirectory = ""
         If openFileDialog1.ShowDialog() = DialogResult.OK Then '
            'ToDo: Error processing original source shown below
            '
            '
            '-----------------------------------------------^--- Illegal whitespace in constant
            textBox1.Text = openFileDialog1.FileName
         End If
      End Sub 'btnBrowse_Click
      
      
      Private Sub btnApply_Click(sender As Object, e As System.EventArgs) Handles Me.btnApply.Click
         Dim s As String = comboBox1.Text
         Dim s2 As Wallpaper.Style = CType([Enum].Parse(GetType(Wallpaper.Style), s, False), Wallpaper.Style)
         
         Wallpaper.Set(New Uri(textBox1.Text), s2)
      End Sub 'btnApply_Click
   End Class 'Form1
    _ 
   
   NotInheritable Public Class Wallpaper
      
      Sub New()
      End Sub 'New 
      Private SPI_SETDESKWALLPAPER As Integer = 20
      Private SPIF_UPDATEINIFILE As Integer = &H1
      Private SPIF_SENDWININICHANGE As Integer = &H2
      
      
      Shared Declare Auto Function SystemParametersInfo Lib "user32.dll" (uAction As Integer, uParam As Integer, lpvParam As String, fuWinIni As Integer) As Integer
       _
      
      Public Enum Style
         '
         'ToDo: Error processing original source shown below
         '
         '
         '---^--- Specified cast is not valid.
         
         
         Public Shared Sub Set(uri As Uri, style As Style)
            Dim s As System.IO.Stream = New WebClient().OpenRead(uri.ToString())
            
            Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(s)
            Dim tempPath As String = Path.Combine(Path.GetTempPath(), "wallpaper.bmp")
            img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp)
            
            Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("")
            If style = Style.Stretched Then '
               'ToDo: Error processing original source shown below
               '
               '
               '------------------------------------------------------------------------^--- Bad escape sequence
               '
               'ToDo: Error processing original source shown below
               '
               '
               '------------------------------------------------------------------------------------------^--- Illegal whitespace in constant
               '
               'ToDo: Error processing original source shown below
               '
               '
               '----------------------------------------^--- Syntax error: ';' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '----^--- Syntax error: ';' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '--------------------------------------------------------^--- Syntax error: ')' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '-----------------------------------------------------------------------^--- Syntax error: ';' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '------------------------------------------------------------------------------^--- Syntax error: ';' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '----^--- Syntax error: ';' expected
               key.SetValue("")
               2.ToString() '
               'ToDo: Error processing original source shown below
               '
               '
               '-------------------^--- Syntax error: ')' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '-----------------------------------^--- Syntax error: ';' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '---------------------------------------------------^--- Syntax error: ';' expected
               key.SetValue("")
               0.ToString() '
            'ToDo: Error processing original source shown below
            '
            '
            '-------------------^--- Syntax error: ')' expected
            '
            'ToDo: Error processing original source shown below
            '
            '
            '----------------------------------^--- Syntax error: ';' expected
            '
            'ToDo: Error processing original source shown below
            '
            '
            '--------------------------------------------------^--- Syntax error: ';' expected
            End If
            
            If style = Style.Centered Then
               key.SetValue("")
               1.ToString() '
               'ToDo: Error processing original source shown below
               '
               '
               '-------------------^--- Syntax error: ')' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '-----------------------------------^--- Syntax error: ';' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '---------------------------------------------------^--- Syntax error: ';' expected
               key.SetValue("")
               0.ToString() '
            'ToDo: Error processing original source shown below
            '
            '
            '-------------------^--- Syntax error: ')' expected
            '
            'ToDo: Error processing original source shown below
            '
            '
            '----------------------------------^--- Syntax error: ';' expected
            '
            'ToDo: Error processing original source shown below
            '
            '
            '--------------------------------------------------^--- Syntax error: ';' expected
            End If
            
            If style = Style.Tiled Then
               key.SetValue("")
               1.ToString() '
               'ToDo: Error processing original source shown below
               '
               '
               '-------------------^--- Syntax error: ')' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '-----------------------------------^--- Syntax error: ';' expected
               '
               'ToDo: Error processing original source shown below
               '
               '
               '---------------------------------------------------^--- Syntax error: ';' expected
               key.SetValue("")
               1.ToString() '
            'ToDo: Error processing original source shown below
            '
            '
            '-------------------^--- Syntax error: ')' expected
            '
            'ToDo: Error processing original source shown below
            '
            '
            '----------------------------------^--- Syntax error: ';' expected
            '
            'ToDo: Error processing original source shown below
            '
            '
            '--------------------------------------------------^--- Syntax error: ';' expected
            End If
            
            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
         End Sub 'Set
      End Class 'Wallpaper
   End Namespace 'ChangeWallpaper